/**
 *  门店券
 */

import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/goods/view/cashier.dart';
import 'package:cbec_app/pages/my/controller/shop_card_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ShopCard extends GetView<ShopCardController>{
  ShopCard({super.key});
  @override
  Widget build(BuildContext context) {
    return GetBuilder<ShopCardController>(builder: (controller){
      return BasePage(
      enablePullDown: true,
      refreshController: controller.baseRefreshCtr,
      onPageRefresh: controller.onPageRefresh,
      title: "门店券",
      iconType: IconType.back,
      paddingTop: 10.w,
      isShowPadding: true,
      children: [
        controller.dataList.isNotEmpty?
          Column(
            children: List.generate(controller.dataList.length, (index){
              return ShopCardItem(title: controller.dataList[index]['couponTitle'], amount: controller.dataList[index]['money'].toString());
            }),
          )
          :const NotFound(),
        
        Positioned(
            bottom: 1,
            child: Container(
              // margin: EdgeInsets.only(left: 18.w,right: 18.w),
              padding: EdgeInsets.fromLTRB(18.w, 10.w, 18.w, 10.w),
              width: 375.w,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    width: 240.w,
                    height: 38.h,
                    padding: EdgeInsets.only(left: 10.w,top: 10.w),
                    decoration: border_radis(Colors.white),
                    child: TextFormField(
                      controller: controller.codetxtController,
                      decoration: descript("请输入兑换码",fontsize: 16),
                    ),
                  ),
                  solidButton("兑换", width: 72.w, height: 35.h, () {
                    controller.storeExchange();
                  })
                ],
              ),
            ))
      ],
    );
    });
  }
}

class ShopCardItem extends StatelessWidget {
  final String title;
  final String amount;

  const ShopCardItem(
      {super.key,
      required this.title,
      required this.amount});

  @override
  Widget build(BuildContext context) {
    return BaseInteractive(
      onClick: () => {
        Tools.showToast("暂无相关接口,正在开发中....")
      },
      childWidget: Container(
        margin: EdgeInsets.only(bottom: 10.w),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10.0),
          image: const DecorationImage(
            image: AssetImage("assets/images/shop_bg.png"),
            fit: BoxFit.cover,
            // colorFilter: ColorFilter.mode(
            //     Colors.grey.withOpacity(0.5), BlendMode.srcOver),
          ),
        ),
        height: 100,
        child: Row(
          children: [
            SizedBox(
              width: 19.w,
            ),
            SizedBox(
              child: BaseImage(
                url: "shop_logo.png",
                width: 44.w,
                height: 44,
                borderRadius: BorderRadius.circular(44 / 2),
              ),
            ),
            SizedBox(
              width: 19.w,
            ),
            SizedBox(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(title,
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.w500,
                          color: Colors.white)),
                  const SizedBox(
                    height: 5,
                  ),
                  Text("余额 ￥$amount",
                      style: TextStyle(
                          fontSize: 13,
                          fontWeight: FontWeight.w400,
                          color: Colors.white))
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
